const Visit = require('../models/visitModel')
const catchAsync = require('../utils/catchAsync')

module.exports = catchAsync(async (req, res, next) => {
  // const ignoredPath = ['/admin']

  // if (!ignoredPath.includes(req.path) || req.method !== 'GET') {
  //   await Visit.create({
  //     ip: req.ip,
  //     userAgent: req.headers['user-agent'],
  //     date: new Date(),
  //   })
  //   console.log('访问量统计成功 ✔️')
  // }

  // 暂时统计所有
  await Visit.create({
    ip: req.ip,
    userAgent: req.headers['user-agent'],
    date: new Date(),
  })

  next()
})
